#include <stdio.h>

void swapVal(int *nums, int *numSize)
{
    int swap = *nums;
    *nums = *numSize;
    *numSize = swap;
}

void innerQuickSort(int *nums, int begin, int end)
{
    if (begin >= end)
    {
        return;
    }
    // 找到当前范围的基准值
    int pivot = nums[begin];

    int backupBegin = begin;
    int backUpEnd = end;
    while (begin < end)
    {
        while (begin < end)
        {
            if (nums[end] >= pivot)
            {
                end--;
            }
            else
            {
                nums[begin] = nums[end];
                begin++;
                break;
            }
        }
        while (begin < end)
        {
            if (nums[begin] >= pivot)
            {
                nums[end] = nums[begin];
                end--;
                break;
            }
            else
            {  
                begin++;
            }
        }
    }

    // 将基准值放到当前索引位置
    nums[begin] = pivot;

    innerQuickSort(nums, backupBegin, begin - 1);
    innerQuickSort(nums, begin + 1, backUpEnd);
}

void quickSort(int *nums, int numSize)
{
    innerQuickSort(nums, 0, numSize - 1);
}

void printArray(int *nums, int numSize)
{
    for (int i = 0; i < numSize; i++)
    {
        printf("%d ", nums[i]);
    }
    printf("\n");
}

int main()
{
    int str[6] = {29, 16, 26, 24, 0, 6};
    int length = sizeof(str) / sizeof(str[0]);
    quickSort(str, length);
    printArray(str, length);
    return 0;
}